package com.itheima.常用API.基本类型包装类;

import java.util.Scanner;

public class 递归求和 {
    public static void main(String[] args) {
        while (true) {
            System.out.println("请输入数字递归n来求和:  ");
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int sum = diGui(n);
            System.out.println("n的递归和为: "+sum);
        }

    }

    private static int diGui(int n) {
        if (n == 1) {
            return 1;
        } else {
            return n + diGui(n - 1);
        }
    }

}
